package pobidz;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class ImagePanel extends JPanel {

	private BufferedImage image;
	private File obrazek = null;
	private BufferedImage obraz;

	public BufferedImage getObraz() {
		return obraz;
	}

	public void setObraz(BufferedImage obraz) {
		this.obraz = obraz;
	}

	public BufferedImage getImage() {
		return image;
	}

	public void setImage(BufferedImage image) {
		this.image = image;
	}

	public File getObrazek() {
		return obrazek;
	}

	public void setObrazek(File obrazek) {
		this.obrazek = obrazek;
	}

	public ImagePanel(File obrazek) throws IOException {
		File plik = new File("C:\\z.jpg");

		if (obrazek == null) {
			System.out.print("pusty");

		}

		else {

			try {

				this.image = ImageIO.read(obrazek);
				System.out.println("zaladowano 1");
				// System.out.println(this.obrazek);
				// System.out.println(this.image);
				System.out.println("przed " + this.obraz);
				this.obraz = this.image;
				System.out.println("przed1 " + this.obraz);

			} catch (IOException ex) {
				// handle exception...
				System.out.println("wyjatek 1");
			}
		}

	}

	public ImagePanel() {
		File plik = new File("C:\\korekta.jpg");

		try {

			this.image = ImageIO.read(plik);
			System.out.println("zaladowano 1");
			// System.out.println(this.obrazek);
			// System.out.println(this.image);
			System.out.println("przed " + this.obraz);
			this.obraz = this.image;
			System.out.println("przed1 " + this.obraz);

		} catch (IOException ex) {
			// handle exception...
			System.out.println("wyjatek 1");
		}

		/*
		 * if(obrazek==null){ System.out.print("pusty");
		 * 
		 * }
		 * 
		 * else{
		 */
		/*
		 * try { this.image = ImageIO.read(new File("C:\\korekta.jpg"));
		 * System.out.println("zaladowano"); } catch (IOException ex) { //
		 * handle exception... // } }
		 */

	}

	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		System.out.println("narysowano");

		// System.out.println(this.obrazek);
		// System.out.println(this.image);
		System.out.println("po " + this.obraz);
		g.drawImage(this.image, 0, 0, this); // see javadoc for more info on the
												// parameters
	}

	public BufferedImage obraz(File obraz) throws IOException {
		BufferedImage obrazek;
		obrazek = ImageIO.read(obraz);
		return obrazek;
	}

}